package com.studio.bill.swiperecyclerdemo.bean;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Bill on 2017/5/28.
 */

public class NonInsuranceBean {
    public String id;
    public String productCode;
    public String img;
    public String url;
    public String tag;
    public String name;
    public String title;
    public String price;
    public String reportId;

    public static List<NonInsuranceBean> getNonInsuranceData(String json){
        List<NonInsuranceBean> nonInsuranceList = new ArrayList<>();

        try{
            JSONObject jsonObj = new JSONObject(json);
            JSONArray jsonArr = jsonObj.optJSONArray("productList");

            if(jsonArr != null){
                for(int i = 0; i < jsonArr.length();i ++){
                    NonInsuranceBean noInsuranceBean = new NonInsuranceBean();
                    JSONObject jsonItem = jsonArr.getJSONObject(i);

                    noInsuranceBean.id = jsonItem.optString("id");
                    noInsuranceBean.productCode = jsonItem.optString("productCode");
                    noInsuranceBean.img = jsonItem.optString("img");
                    noInsuranceBean.url = jsonItem.optString("url");
                    noInsuranceBean.tag = jsonItem.optString("tag");
                    noInsuranceBean.name = jsonItem.optString("name");
                    noInsuranceBean.title = jsonItem.optString("title");
                    noInsuranceBean.price = jsonItem.optString("price");
                    noInsuranceBean.reportId = jsonItem.optString("reportId");
                    nonInsuranceList.add(noInsuranceBean);
                }
            }
            return nonInsuranceList;
        }catch (Exception e){
            e.printStackTrace();
        }

        return nonInsuranceList;
    }
}